package com.yyds.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yyds.common.MyJSON;
import com.yyds.mapper.HospitalDepartmentMapper;
import com.yyds.pojo.HospitalDepartment;
import com.yyds.service.HospitalDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("hospitalDepartmentService")
public class HospitalDepartmentServiceImpl implements HospitalDepartmentService {

    @Autowired
    @Qualifier("hospitalDepartmentMapper")
    private HospitalDepartmentMapper hospitalDepartmentMapper;

    @Override
    public MyJSON<HospitalDepartment> queryHospitalDepartmentService(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page, limit);

        List<HospitalDepartment> hospitalDepartments =  hospitalDepartmentMapper.queryHospitalDepartmentMapper(params);
        PageInfo<HospitalDepartment> pageInfo = new PageInfo<>(hospitalDepartments);
        MyJSON<HospitalDepartment> myJSON = new MyJSON<>();
        myJSON.setCode(0);
        myJSON.setMsg("科室全部信息");
        myJSON.setCount(pageInfo.getTotal());
        myJSON.setData(pageInfo.getList());
        return myJSON;
    }

    @Override
    public Integer insertHospitalDepartmentService(HospitalDepartment hospitalDepartment) {

        return hospitalDepartmentMapper.insertHospitalDepartmentMapper(hospitalDepartment);
    }

    @Override
    public Integer deleteHospitalDepartmentService(Integer department_id) {
        return hospitalDepartmentMapper.deleteHospitalDepartmentMapper(department_id);
    }

    @Override
    public Integer updateHospitalDepartmentService(HospitalDepartment newHospitalDepartment) {
        return hospitalDepartmentMapper.updateHospitalDepartmentMapper(newHospitalDepartment);
    }
}
